package com.wu.demo.controller;

import com.wu.demo.common.annotation.IgnoreAuth;
import com.wu.demo.common.domain.AjaxResult;
import com.wu.demo.common.domain.SensitiveBody;
import com.wu.demo.farmework.config.SystemConfig;
import com.wu.demo.farmework.manager.RequestCounter;
import com.wu.demo.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "ignoreAuth权限TokenToken测试")
@RestController
@RequestMapping("ignore")
@IgnoreAuth
public class IgnoreAuthController {


    @ApiOperation(value = "脱敏测试处理")
    @IgnoreAuth
    @GetMapping("sensitiveTest")
    public AjaxResult sensitiveTest(){
        SensitiveBody body = new SensitiveBody();
        body.setMobile("13041064026");
        body.setIdCard("411126189912355689");
        body.setName("Tom");

        return AjaxResult.success(body);
    }

    @Autowired
    private ISysUserService sysUserService;

    @ApiOperation(value = "不添加IgnoreAuth则需权限校验")
    @GetMapping("test")
    public AjaxResult test(){
        return AjaxResult.success("需权限校验");
    }

    @ApiOperation(value = "添加IgnoreAuth则无需权限校验")
    @IgnoreAuth
    @GetMapping("test1")
    public AjaxResult test1(){
        System.out.println(SystemConfig.getProperty("APPID"));
        return AjaxResult.success("无需权限校验,通过"+SystemConfig.getProperty("APPID"));
    }

    @IgnoreAuth
    @GetMapping("threads")
    public AjaxResult threads() throws InterruptedException {
        return sysUserService.test2();
    }

    @IgnoreAuth
    @GetMapping("getRequestMonitorInfo")
    public AjaxResult getRequestMonitorInfo(){
        return AjaxResult.success(RequestCounter.getCacheInfo());
    }
}
